/*****************************************************************************
 *   Copyright (C) 2008 John Schember <john@nachtimwald.com>                 *
 *                                                                           *
 *   This file is part of niwbillmanager.                                    *
 *                                                                           *
 *   niwbillmanager is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as          *
 *   published by the Free Software Foundation, either version 3 of the      *
 *   License, or (at your option) any later version.                         *
 *                                                                           *
 *   niwbillmanager is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with niwbillmanager. If not, see                                  *
 *   <http://www.gnu.org/licenses/>.                                         *
 *****************************************************************************/

#include <backend.h>

#include <QPluginLoader>

#include <backendinterface.h>

Backend::Backend()
{
    m_name = "";
    m_description = "";
    m_version = "";
    m_remote = false;
    m_static = false;
    m_location = "";
    m_backendInterface = 0;
}

Backend::~Backend()
{
    unloadBackend();
}

void Backend::loadBackend()
{
    if (!isStatic() && !m_location.isEmpty()) {
        QPluginLoader pluginLoader;

        pluginLoader.setFileName(m_location);
        if (pluginLoader.load()) {
            m_backendInterface = qobject_cast<BackendInterface *>
                (pluginLoader.instance());
        }
    }
}

void Backend::unloadBackend()
{
    if (!isStatic()) {
        if (m_backendInterface) {
            delete m_backendInterface;
        }
        m_backendInterface = 0;
    }
}

QString Backend::getName()
{
    return m_name;
}

QString Backend::getDescription()
{
    return m_description;
}

QString Backend::getVersion()
{
    return m_version;
}

bool Backend::isRemote()
{
    return m_remote;
}

bool Backend::isStatic()
{
    return m_static;
}

QString Backend::getLocation()
{
    return m_location;
}

BackendInterface *Backend::getBackendInterface()
{
    return m_backendInterface;
}

void Backend::setName(QString name)
{
    m_name = name;
}

void Backend::setDescription(QString description)
{
    m_description = description;
}

void Backend::setVersion(QString version)
{
    m_version = version;
}

void Backend::setStatic(bool setStatic)
{
    m_static = setStatic;
}

void Backend::setRemote(bool isRemote)
{
    m_remote = isRemote;
}

void Backend::setLocation(QString location)
{
    m_location = location;
}

void Backend::setStaticInterface(BackendInterface *backendinterface)
{
    m_backendInterface = backendinterface;
}
